/**
 * 功能描述
 */

define(function(require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper")
	var instance = {
		initComponent : function(params, widget) {
			var subnav = new Subnav({
				parentNode:".J-subnav",
        		model:{
        			title:"用餐消费记录",
        			items:[{
            			id:"recordDate",
						tip:"预约日期",
						type:"daterange",
						ranges:{
					 		"本月": [moment().startOf("month"), moment().endOf("month")],
					 		"上月": [moment().subtract(1,"months").startOf("month"), moment().subtract(1,"months").endOf("month")],
					 		"本周": [moment().startOf("week"), moment().endOf("week")],
					 		"上周": [moment().subtract(1,"week").startOf("week"), moment().subtract(1,"week").endOf("week")]
						},
						handler : function(time){
							 widget.get("grid").refresh(null,function(data2){
									var k = 0;
					        		for(var i in data2){
					        			k+=(data2[i].totalMoney == null ? 0 : Number(data2[i].totalMoney));
					        		}
					        		var j = parseFloat(k).toFixed(2);
					        		widget.get("grid").setTitle("用餐人数:" + data2.length + "人，共消费:"+ j + "元");
					        		});
						}
            		},{
            			id:"return",
    					type:"button",
    					text:"返回",
    					show:false,
    					handler:function(){
    						widget.hide([".J-detailgrid"]).show([".J-grid"]);
    						widget.get("subnav").hide(["return"]).show(["recordDate"]);
    					}
            		}]
        		}
			});
			widget.set("subnav",subnav);
		}
	};
	module.exports = instance;
});
